package org.ykhl.sdk.appserver;

import org.ykhl.mq.commons.Constants;
import org.ykhl.mq.commons.pusher.MessagePusher;
import org.ykhl.mq.commons.pusher.MessagePusherKafkaImpl;

/**
 * 用于创建{@link MessagePusher}对象的静态工厂类。
 * 
 * @author Zhang Kefei
 *
 */
class MessagePusherFactory {
	private MessagePusherFactory(){}
	private static final String DEFAULT_NAME_SERVER_ADDRESS = Constants.KAFKA_SERVER_LIST_DEV;

	/**
	 * 创建一个MessagePusher实例
	 * 
	 * @param authKey 申请获得的密钥
	 * @return
	 */
	public static MessagePusher newInstance(String authKey){
		return newInstance(DEFAULT_NAME_SERVER_ADDRESS, authKey);
	}

	/**
	 * 创建一个MessagePusher实例
	 *
	 * @param serverAddress 连接的服务器地址
	 * @param authKey 申请获得的密钥
	 * @return
	 */
	public static MessagePusher newInstance(String serverAddress, String authKey){
		return new MessagePusherKafkaImpl(serverAddress, authKey, null, Constants.Role.APPSERVER);
	}

	/**
	 * 创建一个MessagePusher实例
	 *
	 * @param securityFilePath 指定证书文件的路径
	 * @return
	 */
	public static MessagePusher newInstanceWithSecurityFilePath(String securityFilePath) {
		return newInstanceWithSecurityFilePath(DEFAULT_NAME_SERVER_ADDRESS, securityFilePath);
	}

	/**
	 * 创建一个MessagePusher实例
	 *
	 * @param serverAddress 连接的服务器地址
	 * @param securityFilePath 指定证书文件的路径
	 * @return
	 */
	public static MessagePusher newInstanceWithSecurityFilePath(
			String serverAddress, String securityFilePath) {
		return new MessagePusherKafkaImpl(serverAddress, null, securityFilePath, Constants.Role.APPSERVER);
	}
}
